//
//  HMStatusBottomView.m
//  SinaWeiBo
//
//  Created by WGP on 16/4/16.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "HMStatusBottomView.h"

@interface HMStatusBottomView ()

@property(nonatomic,strong)UIButton *retweetBotton;
@property(nonatomic,strong)UIButton *commentBotton;
@property(nonatomic,strong)UIButton *likeBotton;

@end

@implementation HMStatusBottomView

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self setupUI];
    }
    return self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    
    if(self = [super initWithCoder:aDecoder])
    {
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
//    1.添加子控件
    self.retweetBotton = [self buttonWith:@"timeline_icon_retweet" title:@"转发"];
    
    self.commentBotton = [self buttonWith:@"timeline_icon_comment" title:@"评论"];
    
    self.likeBotton = [self buttonWith:@"timeline_icon_unlike" title:@"赞"];
    
    UIImageView *separatorLineFirst = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"timeline_card_bottom_line"]];
    [self addSubview:separatorLineFirst];
    UIImageView *separatorLineSecond = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"timeline_card_bottom_line"]];
    [self addSubview:separatorLineSecond];
    
//    2.添加约束
    [self.retweetBotton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.equalTo(self);
    }];
    
    [self.commentBotton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.width.equalTo(self.retweetBotton);
        make.left.equalTo(self.retweetBotton.mas_right);
    }];
    
    [self.likeBotton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.left.equalTo(self.commentBotton.mas_right);
        make.width.equalTo(self.retweetBotton);
        make.right.equalTo(self);
    }];
    
    [separatorLineFirst mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.retweetBotton.mas_right);
        make.centerY.equalTo(self.retweetBotton);
    }];
    
    [separatorLineSecond mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.commentBotton.mas_right);
        make.centerY.equalTo(self.commentBotton);
    }];
    
}

-(UIButton *)buttonWith:(NSString *)imageName title:(NSString *)title
{
    UIButton *btn = [[UIButton alloc] init];
    
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:HMTimeLabelFontSize];
    
    [btn setBackgroundImage:[UIImage imageNamed:@"timeline_card_bottom_background"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"timeline_card_bottom_background_highlighted"] forState:UIControlStateHighlighted];
    
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [self addSubview:btn];
    return btn;
}

@end
